var vm = new Vue({
    el: '#app',
    data: {
        goodArr: [
            { pic: 'img/3.png', name: '秋刀鱼/斤', price: 35.00, content: 1 },
            { pic: 'img/4.png', name: '鲜带鱼/斤', price: 45.00, content: 1 },
            { pic: 'img/5.png', name: '皮皮虾/斤', price: 85.00, content: 1 },
        ]
    },
    methods: {//定义方法
        add(item) {
            if (item.content > 0 && item.content < 5)
                item.content++;
        },

        minus(item) {
            if (item.content > 1 && item.content <= 5)
                item.content--;
        },
        clearGoodCart() {
            this.goodArr = [];
        }

    },
    computed: {//计算属性
        sumNum() {
            var sum = 0;
            for (var i = 0; i < this.goodArr.length; i++) {
                sum += this.goodArr[i].content;
            }
            return sum;
        },
        sumPrice() {
            var sum = 0;
            for (var i = 0; i < this.goodArr.length; i++) {
                sum += this.goodArr[i].content * this.goodArr[i].price;
            }
            return sum;
        }
    }
})